Hệ thống quản lý trường học bằng PHP / MySQLi

1 <?php
2  include(
'connect.php');
3  error_reporting(
0);//turning off error reporting
4  
if(isset($_POST["Importstudent"])){
5         
6         $filename=$_FILES[
"file"]["tmp_name"];
7
8          
if($_FILES["file"]["size"] > 0)
9          {
10             $file = fopen($filename,
"r");
11             
while (($getData = fgetcsv($file, 20000, ",")) !== FALSE)
12              {
13
14                $sql =
"INSERT into studentstable
15                (student_id,
16                admission_number,
17                 sirname,
18                 firstname,
19                 lastname,
20                 idno,
21                 dateofbirth,
22                 gender,
23                 country_id,
24                 county_id,
25                 constituency_id,
26                 mobile,
27                 email,
28                 address,
29                 zipcode,
30                 course_id,
31                 reg_date,
32                 border,
33                 feepayable)
34                    values(
35                    '"
.$getData[0]."',
36                    '"
.$getData[1]."',
37                    '"
.$getData[2]."',
38                    '"
.$getData[3]."',
39                    '"
.$getData[4]."',
40                    '"
.$getData[5]."',
41                    '"
.$getData[6]."',
42                    '"
.$getData[7]."',
43                    '"
.$getData[8]."',
44                    '"
.$getData[9]."',
45                    '"
.$getData[10]."',
46                    '"
.$getData[11]."',
47                    '"
.$getData[12]."',
48                    '"
.$getData[13]."',
49                    '"
.$getData[14]."',
50                    '"
.$getData[15]."',
51                    '"
.$getData[16]."',
52                    '"
.$getData[17]."'
53                   
54                    )"
;
55                    $result = mysqli_query($db, $sql);
56                 
if(!isset($result))
57                 {
58                     echo
"<script type=\"text/javascript\">
59                             alert(\"Invalid File:Please Upload CSV File.\");
60                             window.location = \"csvstudents.php\"
61                           </script>"
;
62                 }
63                 
else {
64                       
65                 }
66              }
67             
68              fclose($file);
69          }
70     }
71 ?>
72
73 <?php
74  
75  
if(isset($_POST["Exportstudent"])){
76          
77       header(
'Content-Type: text/csv; charset=utf-8');
78       header(
'Content-Disposition: attachment; filename=data.csv');
79       $output = fopen(
"php://output", "w");
80       fputcsv($output, array(
'admission No', 'Sirname', 'Firstname', 'Lastname', 'IDNO','DOB', 'Gender', 'Country ID', 'County ID', 'Constituency ID', 'Mobile','Email','Address','Zipcode','Course ID','Date_Reg','Mode', 'Fee Payable'));
81       $query =
"SELECT admission_number, sirname, firstname, lastname, idno, dateofbirth, gender, country_id, county_id, constituency_id, mobile, email, address, zipcode, course_id, reg_date, border, feepayable
82        
from studentstable ORDER BY admission_number DESC";
83       $result = mysqli_query($db, $query);
84       
while($row = mysqli_fetch_assoc($result))
85       {
86            fputcsv($output, $row);
87       }
88       fclose($output);
89  }
90  
91 ?>


Gõ tìm kiếm nhanh...